package com.yanqu.road.server.cmd.activity.businessreunion;

import com.yanqu.road.pb.activity.BusinessReunionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.businessreunion.BusinessReunionActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2022/4/19 14:49
 */
@Cmd(code = GameProtocol.S_BUSINESS_REUNION_WRITE_RECALL_CODE, desc = "商海重逢填写召回码")
public class WriteRecallCodeCmd extends AbstractCommand {
    private String recallCode;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BusinessReunionProto.WriteRecallCodeReqMsg reqMsg = BusinessReunionProto.WriteRecallCodeReqMsg.parseFrom(packet.getBytes());
        recallCode = reqMsg.getRecallCode();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BusinessReunionActivityModule.class).writeRecallCode(recallCode);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            BusinessReunionProto.WriteRecallCodeRespMsg.Builder respMsg = BusinessReunionProto.WriteRecallCodeRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_BUSINESS_REUNION_WRITE_RECALL_CODE, respMsg);
        }
    }
}
